package com.luweiteng.valiteddemo.entity;

import com.luweiteng.valiteddemo.constant.ErrorCode;
import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResp<T> implements Serializable {
    private static final long serialVersionUID = -5383496429298165111L;

    private Integer status;

    private String msg;

    private T data;


    public static <T> BaseResp<T> fail() {
        BaseResp<T> resp = new BaseResp<>();
        resp.status = -1;
        resp.msg = "服务器开小差了";
        return resp;
    }


    public static <T> BaseResp<T> success(T data) {
        BaseResp<T> resp = new BaseResp<>();
        resp.status = 200;
        resp.msg = "success";
        resp.data = data;
        return resp;
    }

    public static <T> BaseResp<T> success() {
        BaseResp<T> resp = new BaseResp<>();
        resp.status = 200;
        resp.msg = "success";
        return resp;
    }

    public static <T> BaseResp<T> fail(T data, String msg) {
        BaseResp<T> resp = new BaseResp<>();
        resp.status = -1;
        resp.msg = msg;
        resp.data = data;
        return resp;
    }

    public static <T> BaseResp<T> fail(String msg) {
        BaseResp<T> resp = new BaseResp<>();
        resp.status = -1;
        resp.msg = msg;
        return resp;
    }

    public static BaseResp fail(ErrorCode errorCode) {
        BaseResp resp = new BaseResp();
        resp.status = errorCode.getErrorCode();
        resp.msg = errorCode.getErrorMsg();
        return resp;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
}
